package com.qjc.demo.algorithm.布隆过滤器;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.nio.charset.Charset;

/**
 * @ClassName: BloomFilterExample
 * @Author: qjc
 * @Date: 2025/11/26 09:30
 */
public class BloomFilterExample {
    public static void main(String[] args) {
        // 创建布隆过滤器（预计插入1000个元素，误判率0.01）
        BloomFilter<String> filter = BloomFilter.create(
                Funnels.stringFunnel(Charset.forName("UTF-8")),
                1000,
                0.01
        );

        filter.put("apple");
        System.out.println(filter.mightContain("apple"));   // true
        System.out.println(filter.mightContain("banana"));  // false
    }
}
